package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;





import pojo.Area;
import util.DBUtil;

public class AreaDaoImpl implements AreaDao {

	public List<Area> findFiveAreasByName(String name) {
		List<Area> al = new ArrayList<Area>();
		String sql="select * from (select * from areas where area like ?) where rownum <= 5";
		PreparedStatement pst =null;
		ResultSet rs = null;
		Connection conn = null;
		Area a =null;
		int n =0;
		try {
			conn=DBUtil.getConnection();
			pst=conn.prepareStatement(sql);
			pst.setString(1, name+"%");
			rs=pst.executeQuery();
			while(rs.next()){
				a=new Area();
				a.setAreaName(rs.getString("area"));
				al.add(a);
			}
			n=pst.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		finally{
			DBUtil.release(rs, pst, conn);
		}
		return al;
	}

}
